package com.zbkj.admin.task.user;

import cn.hutool.core.date.DateUtil;

import com.zbkj.service.service.UserDividendRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 全民分红 定时任务
 */
@Component("UserDividendTask")
public class UserDividendTask {

    private static final Logger logger = LoggerFactory.getLogger(UserDividendTask.class);

    @Autowired
    private UserDividendRecordService userDividendRecordService;



    /**
     * 每天凌晨1点执行一次
     */
    //@Scheduled(cron = "0 0 14 * * ?")
    //@Scheduled(cron = "0 0 0 * * ?")
    public void processing() {
        logger.info("------------执行奖励------------ - {}", DateUtil.date());
        try {
            // 获取昨天的日期
            LocalDate yesterday = LocalDate.now().minusDays(1);
            // 昨天开始时间：00:00:00
            LocalDateTime startDate = yesterday.atStartOfDay();
            // 昨天结束时间：23:59:59
            LocalDateTime endDate = yesterday.atTime(23, 59, 59);
            // 统计金额
            String startDateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            String endDateStr = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            userDividendRecordService.userDividendTask(null, startDateStr, endDateStr);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("UserDividendTask.Processing" + " | msg : " + e.getMessage());
        }
    }

}
